package plateau;

import java.awt.GridLayout;
import java.awt.Image;
import java.io.IOException;
import java.net.URISyntaxException;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class Plateau2D extends JFrame {
	private static final long serialVersionUID = 1L;
	private Case[][] m_contenuPlateau;
	private JPanel zoneDeJeu;
	private int width;
	private int height;

	public Plateau2D(Case[][] contenuPlateau) throws IOException, URISyntaxException {
		m_contenuPlateau = contenuPlateau;
		
		width = m_contenuPlateau.length;
		height = m_contenuPlateau[0].length;

		zoneDeJeu = new JPanel();
		zoneDeJeu.setLocation(0, 0);
		zoneDeJeu.setLayout(new GridLayout(height, width));
		getContentPane().add(zoneDeJeu);
		
		transparentPanel = new JPanel();
		transparentPanel.setOpaque(false);
		transparentPanel.setBounds(0, 0, 500, 500);
		transparentPanel.setVisible(true);
		getContentPane().add(transparentPanel);
	}

	@Override
	public void repaint() {
		zoneDeJeu.removeAll();
		try {
			for (int y = 0; y < height; y++) {
				for (int x = 0; x < width; x++) {
					Case c = m_contenuPlateau[x][y];
					Image img = c.resource.getImage();
					JLabel imgContainer = new JLabel(new ImageIcon(img));
					zoneDeJeu.add(imgContainer);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		pack();
	}
}
